<div>
	<div class="btn"> 
	     <span>添加附件</span> 
	     <form id='myupload' action='/admin/photoUpload/upload' method='post' enctype='multipart/form-data'>
	    	 <input id="fileupload" type="file" name="mypic">
	     </form>
	</div>
	<div class="progress"> 
	    <span class="bar"></span><span class="percent">0%</span> 
	    <div class="files"></div>
	    <div id="showimg"></div> 
	</div> 
</div>

<script type="text/javascript">
<!--
$(function(){ 
    var bar = $(".bar"); 
    var percent = $(".percent"); 
    var showimg = $("#showimg"); 
    var progress = $(".progress"); 
    var files = $(".files"); 
    var btn = $(".btn span"); 
    $("#fileupload").change(function(){
        $("#myupload").ajaxSubmit({ 
            dataType: 'json',
            beforeSend: function(){
                showimg.empty();
                progress.show();
                var percentVal = '0%';
                bar.width(percentVal);
                percent.html(percentVal);
                btn.html("上传中...");
            }, 
            uploadProgress: function(event, position, total, percentComplete) { 
                var percentVal = percentComplete + '%'; 
                bar.width(percentVal); 
                percent.html(percentVal);
            }, 
            success: function(data) {
            	var percentVal = "100%"; 
                bar.width(percentVal); 
                percent.html(percentVal);
                
                files.html("<b>"+data.name+"("+data.size+"k)</b><span onclick='DU_img(this)' class='delimg' rel='"+data.fileName+"'>删除</span>"); 
                var img = data.path; 
                showimg.html("<img style='border:1px solid #dcdcdc' width='200' height='200' src='"+img+"'>"); 
                btn.html("添加附件"); 
            }, 
            error:function(xhr){
                btn.html("上传失败"); 
                bar.width('0'); 
                files.html(xhr.responseText); 
            } 
        }); 
    }); 
}); 

function DU_img(elem){
	var pic = $(elem).attr("rel"); 
    $.post("/admin/photoUpload/delete",{imagename:pic},function(msg){ 
        if(msg==1){ 
        	$(".files").html("删除成功."); 
        	$("#showimg").empty(); //清空图片 
        	$(".progress").hide(); //隐藏进度条 
        }else{ 
            alert(msg); 
        } 
    }); 
}
-->
</script>